/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-30
 * Time: 19:34
 */
public class test_1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param str string字符串 原串
     * @param arg char字符型一维数组 需替换数组
     * @return string字符串
     */
    public static String formatString(String str, char[] arg) {
        // write code here
        StringBuffer ret = new StringBuffer();
        int i = 0;
        int j = 0;
        while (i < str.length()) {
            char c = str.charAt(i);
            if (c == '%') {
                ret.append(arg[j++]);
                i+=2;
            }else {
                ret.append(c);
                i++;
            }
        }
        if (j<arg.length) {
            while (j<arg.length) {
                ret.append(arg[j++]);
            }
        }
        return ret.toString();
    }

    public static void main(String[] args) {
        String str="A%sC%sE";
        char[] arg={'B','D','F'};
        System.out.println(formatString(str, arg));
    }

}
